package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {
    /**
     * 文章上下架操作
     *
     * @param articleId
     * @param enable =0表示下架，=1表示上架
     *        is_down=0表示上架，is_down=1表示下架
     */
    @Override
    public void downOrUpArticle(Long articleId, Integer enable) {
        if (articleId != null && enable != null){
            //先根据文章id去查询文章配置表
            ApArticleConfig articleConfig = getOne(Wrappers.<ApArticleConfig>lambdaQuery().eq(ApArticleConfig::getArticleId, articleId));
            if (articleConfig != null){
                articleConfig.setIsDown(enable==1?false:true);
                updateById(articleConfig);
            }
        }
    }
}
